package com.zhengshang.web.controller.app;

import com.zhengshang.api.domain.AppGame;
import com.zhengshang.api.domain.AppNavigate;
import com.zhengshang.api.service.IAppNavigateService;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.page.TableDataInfo;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * app首页导航Controller
 *
 * @author zhengshang
 * @date 2022-04-07
 */
@RestController
@RequestMapping("/app/navigate")
public class AppNavigateController extends BaseController {
    @Autowired
    private IAppNavigateService appNavigateService;

    /**
     * 查询app首页导航列表
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppNavigate appNavigate) {
        startPage();
        List<AppNavigate> list = appNavigateService.selectAppNavigateList(appNavigate);
        return getDataTable(list);
    }

    /**
     * 导出app首页导航列表
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:export')")
    @Log(title = "app首页导航", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppNavigate appNavigate) {
        List<AppNavigate> list = appNavigateService.selectAppNavigateList(appNavigate);
        ExcelUtil<AppNavigate> util = new ExcelUtil<AppNavigate>(AppNavigate.class);
        return util.exportExcel(list, "navigate");
    }

    /**
     * 获取app首页导航详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:query')")
    @GetMapping(value = "/{navigateId}")
    public AjaxResult getInfo(@PathVariable("navigateId") Long navigateId) {
        return AjaxResult.success(appNavigateService.selectAppNavigateById(navigateId));
    }

    /**
     * 新增app首页导航
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:add')")
    @Log(title = "app首页导航", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppNavigate appNavigate) {
        return toAjax(appNavigateService.insertAppNavigate(appNavigate));
    }

    /**
     * 修改app首页导航
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:edit')")
    @Log(title = "app首页导航", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppNavigate appNavigate) {
        return toAjax(appNavigateService.updateAppNavigate(appNavigate));
    }

    /**
     * 删除app首页导航
     */
    @PreAuthorize("@ss.hasPermi('app:navigate:remove')")
    @Log(title = "app首页导航", businessType = BusinessType.DELETE)
    @DeleteMapping("/{navigateIds}")
    public AjaxResult remove(@PathVariable Long[] navigateIds) {
        return toAjax(appNavigateService.deleteAppNavigateByIds(navigateIds));
    }


    /**
     * 状态修改
     */
    @PutMapping("/changeNavigateStatus")
    public AjaxResult changeNavigateStatus(@RequestBody AppNavigate appNavigate)
    {
        return toAjax(appNavigateService.updateNavigateStatus(appNavigate));
    }

    /**
     * 查询导航列表
     */
    @GetMapping("/selectAppNavigateByCodes")
    public AjaxResult selectAppNavigateByCodes(String navigateCodes) {
        List<AppNavigate> list = appNavigateService.selectAppNavigateByCodes(navigateCodes);
        return AjaxResult.success(list);
    }

}
